package com.suitsoft.bdms.entity.system;

import java.util.Hashtable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.OrderBy;

import com.suitsoft.bdms.entity.IdEntity;

/**
 * 系统参数类别表实体.
 * 
 * @author Suineg
 */
@Entity
@Table(name = "LW_SYSTEM_CATEGORY")
public class SystemCategory extends IdEntity  {


	
	/**类别代码*/
	private String pmky;
	
	/**类别名称*/
	private String pknm;
	
	/**类别注释*/
	private String memo;

	
	private Set<SystemInfo> systemInfo;

	/**
	 * 以Hashtable形式保存的系统参数对象.
	 * key为主键.
	 */
	
	private Hashtable<Long, SystemInfo> table;

	/**
	 * 以Hashtable形式保存的系统参数对象.
	 * key为pmcd.
	 */
	
	private Hashtable<String, SystemInfo> tableSystemInfo;


	public String getMemo() {
		return memo;
	}

	public String getPknm() {
		return pknm;
	}
	@Column(name = "PMKY", unique = true)
	public String getPmky() {
		return pmky;
	}
	@OneToMany(mappedBy = "systemCategory", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@OrderBy(clause = "pmcd")
	public Set<SystemInfo> getSystemInfo() {
		return systemInfo;
	}

	/**
	 * 以Hashtable形式保存的系统参数对象
	 * KEY=id
	 * 非持久化属性.
	 */
	@Transient
	public Hashtable<Long, SystemInfo> getTable() {
		if (table == null) {
			table = new Hashtable<Long, SystemInfo>();
			for (SystemInfo si : systemInfo) {
				table.put(si.getId(), si);
			}
		}
		
		return table;
	}

	/**
	 * 以Hashtable形式保存的系统参数对象
	 * KEY=pmcd
	 * 非持久化属性.
	 */
	@Transient
	public Hashtable<String, SystemInfo> getTableSystemInfo() {
		if (tableSystemInfo == null) {
			tableSystemInfo = new Hashtable<String, SystemInfo>();
			for (SystemInfo si : systemInfo) {
				tableSystemInfo.put(si.getPmcd(), si);
			}
		}
		
		return tableSystemInfo;
	}
	

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public void setPknm(String pknm) {
		this.pknm = pknm;
	}

	public void setPmky(String pmky) {
		this.pmky = pmky;
	}

	public void setSystemInfo(Set<SystemInfo> systemInfo) {
		this.systemInfo = systemInfo;
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
